//
//  DateCommand.m
//  AsiaDemo
//
//  Created by 123 on 13-9-15.
//  Copyright (c) 2013年 liu. All rights reserved.
//

#import "DateCommand.h"

@implementation DateCommand

+(NSString *)stringFormatFromDate:(NSDate* )date{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    return [formatter stringFromDate:date];
}

+(NSString *)stringFormatFromDate:(NSDate* )date WithStylr:(NSString *)style{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:style];
    return [formatter stringFromDate:date];
}

+(NSDate *)dateFormatFromString:(NSString *)string{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    return [formatter dateFromString:string];
}

+(NSDate *)dateFormatFromString:(NSString *)string WithStylr:(NSString *)style{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:style];
    return [formatter dateFromString:string];
}


/**
 *  字典转get url字符串
 *
 *  @param param 字段
 *
 *  @return 字符串
 */

+ (NSString *)dictTransitoString:(NSDictionary *)param {
    if (param == nil || param.count == 0) {
        return @"";
    } else {
        NSString *dictStr = [NSString stringWithFormat:@"%@", param];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@"{\n    " withString:@""];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@";\n    " withString:@"&"];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@" = " withString:@"="];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@"\n}" withString:@""];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@";" withString:@""];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@"\\\"" withString:@"\""];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@"\"[\"" withString:@"[\""];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@"\"]\"" withString:@"\"]"];
        dictStr = [dictStr stringByReplacingOccurrencesOfString:@"\"" withString:@""];
        return dictStr;
    }
}

@end
